"use strict"
let path = require("path")
module.exports = appInfo => {
	// use for cookie sign key, should change to your own and keep security
	let keys = appInfo.name + "_1534559180073_8748"
	// add your config here
	let middleware = ["error", "safe"]
	let serverConfig = {
		authKey: "aq8spp1d4cu",
		imgBase: "/public/png/",
		host: "http://localhost",
		tokenTime: 6000000,
		uploadPath: undefined,
		imgServerPath: path.join(__dirname, "../app/"),
		imgServer: "http://127.0.0.1:7002"
	}
	serverConfig.uploadPath = path.join(serverConfig.imgServerPath, serverConfig.imgBase)

	let session = {
		renew: true,
	}

	let cluster = {
		listen: {
			port: 7002,
			hostname: "0.0.0.0"
		},
		// workers:4,
	}

	let sequelize = {
		dialect: "mysql", // support: mysql, mariadb, postgres, mssql
		database: "mserver",
		host: "127.0.0.1",
		port: "3306",
		username: "root",
		password: "root",
		timezone: "+08:00"
	}

	let constant = {
		// METHOD
		ERROR_METHOD_NOT_ALLOWED: [1001, "方法不允许"],
		MODULE_OPEN: [801, "模块开启"],
		ERROR_PERMISS_NOT_ALLOWED: [1002, "用户无相关权限"],
		ERROR_WAY_NOT_ALLOWED: [1003, "不合法操作"],

		// 字段缺少
		ERROR_PARAM_UPLOAD_MISS: [2001, "参数缺失"],
		ERROR_UPLOAD_FAIL: [2002, "上传失败"],
		// 错误码
		ERROR_APP_NOEXIST: [802, "应用没有存在"],
		ERROR_USER_LOGIN_FAIL: [3001, "没有登录"],
		ERROR_USER_CREATE_EXIST: [3002, "账号已经存在"],
		ERROR_USER_CODE_EXPIRE: [3003, "验证码过期或者不存在"],
		ERROR_USER_TOKEN_EXPIRE: [3003, "登录超时"],
		ERROR_USER_CODE_NOMATCH: [3003, "验证码不正确"],
		ERROR_USER_ACCOUNT_NOEXIST: [3003, "用户不存在"],
		ERROR_USER_PASSWORD_NOMATCH: [3003, "密码错误"],
		ERROR_SQL: [5000, "尝试数据库操作出错"],
		ERROR_SQL_CREATE: [5002, "尝试插入数据出错"],
		ERROR_SQL_UPDATE: [5003, "尝试更新数据出错"],
		ERROR_DB_MISS: [5004, "数据完整性异常"],
		WECHAT_CODE_REUSE: [5100, "微信异常code"],
		WECHAT_GENIMG_FAIL: [5101, "生成图片错误"],
		NORMAL: [0, "正常"],
		EMPIRE_USER_MISS: [11001, "相关用户不存在"],
		EMPIRE_USER_SET_INVITE_REPEAT: [11101, "你已经设置了邀请人"],
		EMPIRE_USER_INVITER_MISS: [11102, "你不是他的邀请人"],
		EMPIRE_USER_SET_INVITER_ERROR: [11103, " 不允许邀请自己"],
		EMPIRE_USER_INVITER_REWARD_RECEIVE: [11103, "已领取奖励"],
		EMPIRE_HELP_MISS: [11201, "开启助力失败"],
		EMPIRE_HELP_FAIL: [11202, "助力好友失败"],
		EMPIRE_HELP_SET_ERROR: [11203, "自己助力自己"],
		EMPIRE_SIGN_FAIL: [11301, "重复签到"],
		EMPIRE_TSK_OUT_ORDER: [11401, "超出顺序"],
		EMPIRE_TSK_NOFINISH: [11402, "未完成任务不可以领取奖励"],
		EMPIRE_TSK_REC_REPEAT: [11403, "重复领取奖励"],
		EMPIRE_NO_SELL_BEFORE: [11404, "未曾经出售"],
	}

	let multipart = {
		fileSize: "3mb",
		fileExtensions: [".jpg", ".jpeg", ".png", ".gif", ".bmp"]
	}
	let cors = {
		allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH",
		credentials: true
	}

	let redis = {
		client: {
			port: 6379, // Redis port
			host: "127.0.0.1", // Redis host
			password: "",
			db: 0
		}
	}

	let redisPrefix = {
		gameUser: "gameUser.",
		wxUser: "wx##",
		// adCount: "adCount##"
	}
	let empire = {
		moduleId: 1
	}
	const config = exports = {
		keys, constant, sequelize, session, middleware, serverConfig, multipart, cors, cluster, redis, empire, redisPrefix
	}

	return config
}
